﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MediaRecommender.Model;
using MediaRecommender.Security;

namespace MediaRecommender.Controller
{
    public class LoginController
    {
        private UserCollection _userCollection = UserCollection.Instance;

        public LoginController()
        { }

        // The login method, taking in a username and password
        public bool Login(string username, string pass)
        {
            // Tries to get the user from the collection
            User returnedUser = (UserCollection.Instance.GetUser(username));

            // If the user was not retrieved, it must mean no user with the indicated username exists
            if (returnedUser == null)
                return false;

            // Tries to validate the indicated password, checking with the hashed password from the retrieved user
            if (PasswordHash.ValidatePassword(pass, returnedUser.Password))
                return true;
            return false;
        }

    }
}